<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>关于我上传与修改</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="<< url_for('static', filename='layui/css/layui.css',t='1483944306685') >>" media="all">
  <link rel="stylesheet" href="<< url_for('static', filename='layui/css/notice.css',t='879425') >>" media="all">
  <style>
    #slide_percent .layui-slider-input{
      top: 0px;
    }
  </style>
</head>
<body>
  <div class="layui-form" lay-filter="layuiadmin-form-tags" id="layuiadmin-app-form-tags" style="padding-top: 30px; text-align: center;">
    <div class="layui-form-item">
      <label class="layui-form-label">图片</label>
      <div class="layui-input-inline">
        << form.toolImgSrc >>
      </div>
      <div class="layui-input-inline layui-btn-container" style="width: auto">
        <button type="button" class="layui-btn" id="imgSrc_upload"><i class="layui-icon">&#xe67c;</i>上传图片</button>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">百分比</label>
      <div class="layui-input-inline">
        <div id="slide_percent" style="padding-top: 15px;padding-left: 10px;"></div>
        << form.percent >>
      </div>
    </div>
     <div class="layui-form-item">
        << form.csrf_token >>
       <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
    </div>
  </div>
 <script src="/static/layui/layui.all.js?t=1483944306685" charset="utf-8" type="text/javascript"></script>
<script>
    var $ = layui.jquery, i = layui.view,
            element = layui.element,
            layer = layui.layer, form = layui.form,slider=layui.slider,upload=layui.upload;
    var slide_percent =slider.render({elem: '#slide_percent',input:true,change: function(value){
    $("#percent").val(value);
  }});
    var r=$('#toolImgSrc');
    upload.render({
        url: "<< url_for('main.upload') >>?action=uploadimage",
        elem: "#imgSrc_upload",
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        layer.load(); //上传loading
      }
      ,acceptMime: 'image/*'
      ,accept:'images'
      ,progress: function(n, elem){
        var percent = n + '%';//获取进度百分比
        element.progress('demo', percent); //可配合 layui 进度条元素使用
      }
       ,done: function(t) {
            1 == t.status ? r.val(t.data.src) : layui.msg(t.msg, {
                icon: 5
            })
        layer.closeAll('loading'); //关闭loading
        }
        ,error: function(index, upload){
        layer.msg('网络异常');
        layer.closeAll('loading'); //关闭loading
      }
    });
    <% if tool_obj %>
    slide_percent.setValue(<< tool_obj.percent >>)
    <% endif %>
     <% if tool_obj %>
    //监听提交
    form.on('submit(layuiadmin-app-form-edit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
      console.log('1');
      //提交 Ajax 成功后，关闭当前弹层并重载表格
      $.ajax({
          url:"<< url_for('admin.ToolEdit',Id=tool_obj.id) >>",
          type:'post',
          data:field,
          dataType: 'json',
          success: function (returnData) {
                if (returnData.status == 1) {
                    layer.msg('发布成功');
                    parent.layui.table.reload('tool'); //重载表格
                    parent.layer.close(index); //再执行关闭
                }
                else {
                    layer.msg(returnData.info)
                }
           }
      });
    });
      <% else %>
          //监听提交
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

      //提交 Ajax 成功后，关闭当前弹层并重载表格
      $.ajax({
          url:"<< url_for('admin.ToolAdd') >>",
          type:'post',
          data:field,
          dataType: 'json',
          success: function (returnData) {
                if (returnData.status == 1) {
                    layer.msg('发布成功');
                    parent.layui.table.reload('tool'); //重载表格
                    parent.layer.close(index); //再执行关闭
                }
                else {
                    layer.msg(returnData.info)
                }
           }
      });
    });
      <% endif %>
  </script>
</body>
</html>